package com.workcell.workdata.xthings.mapper;

import com.workcell.workdata.common.data.datascope.WorkdataBaseMapper;
import com.workcell.workdata.xthings.entity.CodeChainnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 二维码码库
 *
 * @author 廖博文
 * @date 2022-11-30 09:34:00
 */
@Mapper
public interface CodeChainnumMapper extends WorkdataBaseMapper<CodeChainnum> {
    @Select("select count(1) from t_code_chainnum where hardware_type=#{hardwareType} and (create_time between #{startTime} and #{endTime})")
    Integer getByTypeAndCreateTime(@Param("hardwareType") String hardwareType, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

    @Select({"<script>",
            "select count(1) from t_code_chainnum where hardware_type=#{hardwareType} ",
            "<if test='useState!=null'>",
            "and use_state = #{useState}",
            "</if>",
            "</script>"})
    Integer getByTypeAndUseState(@Param("hardwareType") String hardwareType, @Param("useState") String useState);

    @Select("select * from t_code_chainnum where use_state = #{useState} ")
    List<CodeChainnum> getByUseState(@Param("useState") String useState);

    Map<String, Object> deviceDetail(@Param("deviceNo") String deviceNo, @Param("hardwareType") String hardHareType);

    @Select("select * from t_code_chainnum where chain_num =#{deviceNo} and hardware_type=#{hardwareType}")
    CodeChainnum getByChainnumAndHardwareType(@Param("deviceNo") String deviceNo, @Param("hardwareType") String hardHareType);
}
